package com.tgy.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: tgy
 * @Date: 12/1/20 9:17 AM
 *
 * https://leetcode-cn.com/problems/two-sum/
 */
public class _1_两数之和 {

    public int[] twoSum(int[] nums, int target) {

        if (nums == null || nums.length == 0) {

            return new int[0];
        }

        Map<Integer,Integer> map = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {

            if (map.containsKey(nums[i])) {

                return new int[]{map.get(nums[i]),i};
            }

            map.put(target - nums[i],i);
        }


        return new int[0];
    }

    public static void main(String[] args) {

        System.out.println("1111");
    }
}
